﻿
//=======================================================================
// <copyright file="APIHelper.cs" company="Samuel Chen Studio">
//     Copyright (c) Samuel Chen Studio. All rights reserved.
//     author   : Samuel Chen
//     version  : 1.0
//     contact  : http://www.SamuelChen.net, samuel.net@gmail.com
// </copyright>
//=======================================================================

using System.Net;
using System.IO;
using System.Diagnostics;
using System;
namespace Net.SamuelChen.SharpTweet {

    /// <summary>
    /// A helper class to process twitter APIs.
    /// </summary>
    internal class APIHelper {

        public APIHelper() {
        }

        public APIHelper(bool https, APIFormat format) {
            this.Https = https;
            this.Format = format;
        }

        /// <summary>
        /// Gets or sets the flag of whether use a security https connection. 
        /// Default is false.
        /// </summary>
        public bool Https = false;

        /// <summary>
        /// Gets or sets the prefer response format.
        /// Defalut is XML.
        /// </summary>
        public APIFormat Format = APIFormat.XML;

        /// <summary>
        /// Gets twitter base url.
        /// </summary>
        public string BaseUrl {
            get {
                if (Https)
                    return "https://twitter.com";
                else
                    return "http://twitter.com";
            }
        }

        /// <summary>
        /// Get the format string piece.
        /// </summary>
        /// <returns>the format string piece.</returns>
        public string GetFormatString {
            get { return Format.ToString().ToLower(); }
        }

        /// <summary>
        /// Generate the uri of specified API.
        /// </summary>
        /// <param name="apiPath">specified API path.</param>
        /// <returns>The uri.</returns>
        public string GenerateUri(string apiPath) {
            return string.Format("{0}{1}.{2}", BaseUrl, apiPath, GetFormatString);
        }

        /// <summary>
        /// Generate the uri of specified API.
        /// </summary>
        /// <param name="apiPath">specified API path.</param>
        /// <param name="screenName">user screen name.</param>
        /// <returns>the uri</returns>
        public string GenerateUri(string apiPath, string screenName) {
            return string.Format("{0}{1}/{2}.{3}", BaseUrl, apiPath, screenName, GetFormatString);
        }

    }

}